﻿#ifndef LVIEW
#define LVIEW

#include "DataSourceObject.h"
#include <QtQml/QQmlExtensionPlugin>
#include <QtQml/qqml.h>
#include <qdebug.h>
#include <qdatetime.h>
#include <qbasictimer.h>
#include <qcoreapplication.h>
#include <QVariant>
#include <QString>
#include <QAbstractListModel>
#include <QJsonDocument>

class LView : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit LView();
    ~LView(){}

    Qt::ItemFlags  flags(const QModelIndex &index) const;
    bool setData(const QModelIndex &index, const QVariant &value,int role = Qt::EditRole);

    enum datasourceRoles {
        mailRole = Qt::UserRole+1,
        nameRole,
        pwdRole,
        imgRole
    };

    QHash<int, QByteArray> roleNames() const;
//    int rowCount(const QModelIndex &parent) const;

    QVariant data(const QModelIndex &index, int role) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    void insertValue(const QString &mail,const QJsonObject &data){
        beginInsertRows(QModelIndex(), rowCount(), rowCount());
        m_onlineUser.append(DataSourceObject(data));
        endInsertRows();
    }

    void removeValue(const QString &key){
        beginResetModel();
        m_onlineUser.removeAll(DataSourceObject(key));
        endResetModel();
    }

    Q_INVOKABLE QString getMailImg(const QString &mail);
    Q_INVOKABLE QString getMailName(const QString &mail);
private:


signals:


public slots:


private:
    QList<DataSourceObject> m_onlineUser;
};
#endif // LVIEW

